package com.zgkj.Zip.tools;

import java.util.HashMap;
import java.util.Map;

public class SqlUtil {


	public static String getInsetSql(String tableName,HashMap<String, String> paraMap){
		StringBuffer stringBuffer = new StringBuffer(" insert into ");
		stringBuffer.append(tableName).append("");
		StringBuffer keyBuffer = new StringBuffer("(");
		StringBuffer valueBuffer = new StringBuffer("(");
		for (Map.Entry<String, String> entry : paraMap.entrySet()) {
			String keyString = entry.getKey();
			String valueString = entry.getValue();
			if(keyString.indexOf("%")>0){ //数字
				keyString = keyString.replace("%", "");
				valueString = valueString;

			}else{
				valueString = "'"+valueString+"'";
			}

			keyBuffer.append(keyString).append(",");
			valueBuffer.append(valueString).append(",");
		}

		stringBuffer.append(keyBuffer).append(") values ").append(valueBuffer).append(")");
		System.out.println(stringBuffer.toString().replace(",)", ")"));
		return stringBuffer.toString().replace(",)", ")");
	}

	public static String getIntStr(String str){
		if(str==null){
			return "0";
		}
		if("0".equals(str)){
			return str;
		}
		if(!StringUtil.isNumeric(str.replace(".", ""))){
			return "0";
		}
		if(str.indexOf(".")>0){
			String endStr = str.substring(str.indexOf(".")+1,str.length());
			if(endStr.length()==1){
				str = str.replace(".", "")+"0";
			}else if(endStr.length()==2){
				str = str.replace(".", "");
			}else if(endStr.length()>2){
				str = str.substring(0,str.indexOf(".")+2+1).replace(".","");
			}
		}else{
			str = str+"00";
		}

		return Integer.parseInt(str)+"";
	}


	public static void main(String[] args) {
		HashMap<String, String> aHashMap= new HashMap<>();

//		aHashMap.put("a", "123123");
//		aHashMap.put("b%", "22222");
//		aHashMap.put("c", "1223");
//		System.out.println(SqlUtil.getInsetSql("abc", aHashMap));

		System.out.println(getIntStr("123.123"));



	}
}
